﻿@model LuxDiner.Model.Products.ProductModel


<div class="GeneralEdit" id="fmProduct">
    <ul>
        <li>
            <label for="txtProductNo">产品编码：</label>
            <input type="text" class="k-textbox" id="txtProductNo" name="productNo" value="@Model.ProductNo" maxlength="50" pattern=".{2,}" required validationMessage="请输入产品编码" />
            <span class="k-invalid-msg" data-for="productNo"></span>
        </li>
        <li>
            <label for="txtProductName">产品名称：</label>
            <input type="text" class="k-textbox" id="txtProductName" name="productName" value="@Model.ProductName" maxlength="50" pattern=".{2,}" required validationMessage="请输入产品名称" />
            <span class="k-invalid-msg" data-for="productName"></span>
        </li>
        <li>
            <label for="txtUnitName">单位名称：</label>
            <input type="text" class="k-textbox" id="txtUnitName" name="unitName" value="@Model.UnitName" maxlength="10" pattern=".{1,}" required validationMessage="请输入单位名称" />
            <span class="k-invalid-msg" data-for="unitName"></span>
        </li>
        <li>
            <label for="txtAssistantUnitName">辅助单位名称：</label>
            <input type="text" class="k-textbox" id="txtAssistantUnitName" name="assistantUnitName" value="@Model.AssistantUnitName" maxlength="10" pattern=".{1,}" validationMessage="请输入辅助单位名称" />
            <span class="k-invalid-msg" data-for="assistantUnitName"></span>
        </li>
        <li>
            <label for="txtAssistantUnitRate">换算比率：</label>
            <input type="number" id="txtAssistantUnitRate" name="assistantUnitRate" value="@Model.AssistantUnitRate" />
            <span class="k-invalid-msg" data-for="assistantUnitRate"></span>
        </li>
        <li>
            <label for="ddlCategories">所属分类：</label>

            <select id="ddlCategories" multiple="multiple" data-placeholder="选择分类...">
                @foreach (var cat in (LuxDiner.Model.Products.ProductCategoryCollection)ViewBag.Categories)
                {
                    <option value="@cat.ID" @((Model.Categories != null && Model.Categories.Any(p => p.ID == cat.ID)) ? "selected=\"selected\"" : "") >@cat.CategoryName</option>    
                }
            </select>
        </li>
        <li>
            <label for="txtSortIndex">排序号：</label>
            <input type="number" class="k-textbox" id="txtSortIndex" name="sortIndex" value="@Model.SortIndex" min="0" required validationMessage="请输入排序号"/>
            <span class="k-invalid-msg" data-for="sortIndex"></span>
        </li>
        <li>
            <label for="ddlStatus">状态：</label>
            <select id="ddlStatus">
                <option value="1" @(Model.Status==1?"selected='selected'":"")>正常</option>
                <option value="2" @(Model.Status==2?"selected='selected'":"")>禁用</option>
            </select>
        </li>
        <li class="editButtons">
            <button id="btnSaveProduct" class="k-button"><span class="k-icon k-i-tick"></span><span>确认提交</span></button>
            &nbsp;&nbsp;
            <button class="k-button" onclick="CancelGeneralEdit();"><span class="k-icon k-i-cancel"></span><span>&nbsp;返&nbsp;回</span></button>
        </li>
    </ul>
</div>

<script class="init">
    $("#ddlStatus").kendoDropDownList();
    $("#txtAssistantUnitRate").kendoNumericTextBox({
        format:"n0"
    });
</script>

<script class="save_product">
    $("#ddlCategories").kendoMultiSelect();

    $(function () {
        var validator = $("#fmProduct").kendoValidator().data("kendoValidator");
        $("#btnSaveProduct").click(function (e) {
            if (validator.validate()) {
                var values = {
                    productID: "@Model.ID",
                    productNo: $("#txtProductNo").val(),
                    productName: $("#txtProductName").val(),
                    categories: $("#ddlCategories").data("kendoMultiSelect").value().join(','),
                    unitName: $("#txtUnitName").val(),
                    assistantUnitName: $("#txtAssistantUnitName").val(),
                    assistantUnitRate: $("#txtAssistantUnitRate").val(),
                    status: $("#ddlStatus").data("kendoDropDownList").value(),
                    sortIndex: $("#txtSortIndex").val()
                };

                Whale.Remote.Operation({
                    url: "/Products/Product/Save",
                    parameters: values,
                    success: function (result) {
                        wndGeneralEdit.close();
                        if ($("#grid_product").length > 0)
                            $("#grid_product").data("kendoGrid").dataSource.read();
                    },
                    error: function (msg) {
                        wndGeneralInformation.content(msg).open();
                    }
                });
            }
            return false;
        });
    });
</script>
